package org.grow.mvcpractise;

import org.grow.mvcpractise.filter.FirstFilter;
import org.grow.mvcpractise.filter.SecondFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.servlet.Filter;

@SpringBootApplication
public class MvcpractiseApplication implements WebMvcConfigurer {

    public static void main(String[] args) {
        SpringApplication.run(MvcpractiseApplication.class, args);
    }



    @Autowired
    private FirstFilter firstFilter;
    @Bean
    public FilterRegistrationBean firstFilterBean(){
        FilterRegistrationBean<Filter> bean = new FilterRegistrationBean<>();
        bean.setFilter(firstFilter);
        bean.setOrder(1);
        return bean;
    }
    @Autowired
    private SecondFilter secondFilter;
    @Bean
    public FilterRegistrationBean secondFilterBean(){
        FilterRegistrationBean<Filter> bean = new FilterRegistrationBean<>();
        bean.setFilter(secondFilter);
        bean.setOrder(2);
        return bean;
    }
    @Autowired
    private SampleInterceptor sampleInterceptor;
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(sampleInterceptor);
    }
}
